package com.test.demo.controller;

import com.test.demo.VO.InformationPageVO;
import com.test.demo.VO.ResultVO;
import com.test.demo.entity.monEntity.Information;
import com.test.demo.service.MonNewsService;
import com.test.demo.util.ResultVOUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class NewController {
    @Autowired
    private MonNewsService monNewsService;
    @GetMapping("/getArticle")   //分页查找需要的分页信息
    public ResultVO modelAndView(@RequestParam(value = "page",defaultValue ="1" ) String page,
                                 @RequestParam(value = "size",defaultValue ="10") String size) {
        InformationPageVO informationPageVO = new InformationPageVO();
        PageRequest request = new PageRequest(Integer.valueOf(page)-1,Integer.valueOf(size));
        Page<Information> informationList = monNewsService.findByDisplay(0,request);
        if(Integer.valueOf(page)<informationList.getTotalPages()){   //是否还有内容
            informationPageVO.setPageContent("true");
        }
        else{
            informationPageVO.setPageContent("false");
        }
        informationPageVO.setPage(page);
        informationPageVO.setSize(size);
        informationPageVO.setInformationList(informationList.getContent());
        log.info("informationPageVO={}",informationPageVO);
        return ResultVOUtil.success(informationPageVO);
    }
}
